#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{

	int arr[1000][3], sum[1000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
		sum[i] = arr[i][0] + arr[i][1] + arr[i][2];
	}

	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n - 1; j++)
		{
			if (abs(arr[i][0] - arr[j][0]) <= 5 &&
				abs(arr[i][0] - arr[j][1]) <= 5 &&
				abs(arr[i][0] - arr[j][2]) <= 5 &&
				abs(arr[i][1] - arr[j][0]) <= 5 &&
				abs(arr[i][1] - arr[j][1]) <= 5 &&
				abs(arr[i][1] - arr[j][2]) <= 5 &&
				abs(arr[i][2] - arr[j][0]) <= 5 &&
				abs(arr[i][2] - arr[j][1]) <= 5 &&
				abs(arr[i][2] - arr[j][2]) <= 5 &&
				abs(sum[i] - sum[j]) <= 10)
			{
				cnt++;
			}
		}
	}
	cout << cnt;
	return 0;
}